package cn.ylg.com.baisibudeijie.pro.login.view.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import cn.ylg.com.baisibudeijie.MainActivity;
import cn.ylg.com.baisibudeijie.R;
import cn.ylg.com.baisibudeijie.pro.base.view.BaseFragment;
import cn.ylg.com.baisibudeijie.pro.login.view.LoginActivity;

/**
 * Created by MyPC on 2016/10/24.
 */
public class LogoFra extends BaseFragment implements View.OnClickListener{
    public final static String ARG_KEY = "ARG";

    public final static int ARG_TYPE_FIRST = 0;
    public final static int ARG_TYPE_LOGINED = 1;

    private Button btnSignUp;//注册
    private Button btnSignIn;//登录
    //tiaozhuan
    private Handler handler = new Handler();
    public int currentFlag = 0;
    @Override
    public int getContentView() {
        return R.layout.fra_logo;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle arguments = getArguments();
        currentFlag = arguments.getInt(ARG_KEY);
    }

    @Override
    public void initContentView(View viewContant) {
        btnSignIn = (Button) viewContant.findViewById(R.id.btn_sign_in);
        btnSignUp = (Button) viewContant.findViewById(R.id.btn_sign_up);
        btnSignIn.setOnClickListener(this);
        btnSignUp.setOnClickListener(this);
        //第一次登录;
        if (currentFlag == ARG_TYPE_FIRST) {
            btnSignIn.setVisibility(View.VISIBLE);
            btnSignUp.setVisibility(View.VISIBLE);
        } else {
            btnSignIn.setVisibility(View.GONE);
            btnSignUp.setVisibility(View.GONE);
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    // // 开启服务
                    // if (!CommonUtil.isServiceRunning(getActivity(),
                    // ChatCoreService.class)) {
                    // getActivity()
                    // .startService(
                    // new Intent(getActivity(),
                    // ChatCoreService.class));
                    // }
                    startActivity(new Intent(getActivity(), MainActivity.class));
                    getActivity().finish();
                }
            }, 1500);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_sign_in:
                ((LoginActivity)getActivity()).go2SignIn();
                break;
            case R.id.btn_sign_up:
                ((LoginActivity)getActivity()).go2SignUp();
                break;
        }
    }


}
